# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=thefuck
pkgver=3.32
pkgrel=5
pkgdesc="Magnificent app which corrects your previous console command"
arch=('any')
url="https://github.com/nvbn/thefuck"
license=('MIT')
depends=('python-colorama' 'python-decorator' 'python-psutil' 'python-pyte'
'python-six')
makedepends=('python-build' 'python-installer' 'python-setuptools' 'python-wheel')
checkdepends=('python-pytest-mock' 'python-mock' 'python-pexpect' 'go')
source=("https://github.com/nvbn/thefuck/archive/$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('961b9b6dc374cc0b854698455f688cf110adb21cfebd4cb645eb5f1ce11c14de6699bb4d40de86a5f9461273cbfc2eea318a9d437f803dc578dd431966cf26c1')

build() {
  cd thefuck-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd thefuck-$pkgver

  # Hack distribution test by installing it and set PYTHONPATH afterwards
  python -m installer --destdir="$PWD/tmp_install" dist/*.whl

  # Hack $HOME as it's / in the chroot and not writable
  cp tests/test_conf.py "$srcdir/test_conf.py.bak"
  sed -i "s|data = {}|data = {'HOME': '$srcdir'}|" tests/test_conf.py
  local python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
  LC_CTYPE=en_US.utf8 PYTHONPATH="$PWD/tmp_install/usr/lib/python${python_version}/site-packages:$PYTHONPATH" py.test tests
  mv "$srcdir/test_conf.py.bak" tests/test_conf.py
}

package() {
  cd thefuck-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl

  install -Dm644 LICENSE.md "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.md
}

# vim:set ts=2 sw=2 et:
